package com.rayo.accesscontrollercopy.model.db.dao;

import com.rayo.accesscontrollercopy.model.db.DbHelp;
import com.rayo.accesscontrollercopy.model.db.bean.CurrentUserData;

import java.util.List;

/**
 * Created by lyc-pc on 17/7/7.
 */

public class CurrentUserImpl implements CurrentUserDao {
    @Override
    public void add(CurrentUserData currentUserData) {
        DbHelp.insert(currentUserData);
    }

    @Override
    public void deleteByTagid(String tagid) {
        DbHelp.deleteWhere(CurrentUserData.class, "tagid",
                new String[]{String.valueOf(tagid)});
    }

    @Override
    public List<CurrentUserData> findAll() {
        List<CurrentUserData> list = DbHelp.getQueryAll(CurrentUserData.class);
        return list;
    }

    @Override
    public CurrentUserData findByUserId(String userid) {
        List<CurrentUserData> list = DbHelp.getQueryByWhere(CurrentUserData.class,"user",new String[]{userid});
        if(list.size()>0){
            return list.get(0);
        }
        return null;
    }

    @Override
    public void deleteByKeysn(String sn) {
        DbHelp.deleteWhere(CurrentUserData.class, "key",
                new String[]{String.valueOf(sn)});
    }

    @Override
    public void delete(CurrentUserData currentUserData) {
        DbHelp.delete(currentUserData);
    }
}
